define(function(require,exports,module){

	//检测类
	var Auth = require('qd-auth-1.0');
	//Animate Pack
	var Animate = require('/plugins/extend/Animate');
	var saveAjaxDate = {};
	
	
	var wait = 60;
	var returnflag = false;
	get_code_time = function (elem) {
		if (wait == 0 ||returnflag==true) {
			$(elem).val("重新发送");
			$(elem).removeClass("addCardVaildCodeDis");
			$(elem).attr("disabled",false);
			wait = 60;
		} else {
			$(elem).val("("+wait+")秒后重新获取");
			$(elem).addClass("addCardVaildCodeDis");
			$(elem).attr("disabled",true);
			wait--;
			setTimeout(function() {
				get_code_time(elem);
			}, 1000);
		}
	};
	$("#getPhoneVcode").click(function(){
		var _that = this;
		if($("select[name='city']").val()==""||$("select[name='province']").val()==""){
    		layer.alert('请选择开户地址');
			return false;
		}else if($("input[name='bankNo']").val().length<12){
    		layer.alert('请正确填写银行账号');
			return false;
		}else if(!/^1[3578]\d{9}$/.test($("#mobilephone").val())){
    		layer.alert('请正确填写手机号码');
			return false;
		}
		returnflag = false;
		get_code_time(_that);
		var ajaxdata={
				"dictBankId":$("select[name='dictBankId']").val(),
				"province":$("select[name='province']").val(),
				"city":$("select[name='city']").val(),
				"bankNo": $("input[name='bankNo']").val(),
				"mobilephone":$("input[name='mobilephone']").val()	
		};
		$.ajax({
			url:"/tpp/tppSinaAction/sendBindBankCode.html",
			type:"post",
			dataType:"json",
			data: ajaxdata,
			success: function(data){
				if(data.result==true){
					$("#myticket").val(data.ticket);
					saveAjaxDate = ajaxdata;
				}else{
					returnflag = true;
                    layer.alert(data.msg);
				}
			}
		});
    });
	//表单验证 
		
		$("#addBankForm").validate({
			rules:{
				city:{
					required:true
				},
				bankNo:{
					required:true,
					rangelength:[12,19]
				},
				comfirmAccount:{
					required:true,
					equalTo:"#infoyhzh"
				},
				mobilephone:{
					required:true,
					isMobile:true
				},
				code:{
					required:true
				}
				
			},
			messages:{
				city:{
					required:"请选择开户地址"
				},
				bankNo:{
					required:"请输入银行账号",
					rangelength:"请输入{0}~{1}位银行账号"
				},
				comfirmAccount:{
					required:"确认银行账号",
					equalTo:"两次输入的银行卡不一致，请重新输入"
				},
				mobilephone:{
					required:"请输入手机号",
					isMobile:"手机号码格式不正确"
				},
				code:{
					required:"请输入验证码"
				}
			},
			errorElement:"em",
			errorPlacement:function(error,element){
				error.appendTo(element.parent().find("span"));
			},
			submitHandler:function(form,event,validator){
				if($("input[name='cardType']:checked").val()=="1"){
					if($("#myticket").val()==""){
						layer.alert("请先获取验证码！");
						return;
					}
					
					for(var name in saveAjaxDate){
						if($("[name="+name+"]").val()!=saveAjaxDate[name]){
							$("#myticket").val("");
							saveAjaxDate[name] = $("[name="+name+"]").val();
							layer.alert("信息已修改，请重新获取验证码！");
							return;
						}
					}
					
				}
				$(form).ajaxSubmit({
					dataType:'json',
					success:function(data){
						//单点登录检测
						if(Auth.checkLogin(arguments[0]) == false) {return ;}


						if(data.result){
							/*$(form).hide();
							$("#taken").val(data.taken);
							$("#addBankFormSec").show();*/
							window.layer.open({
							    type: 1,
							    closeBtn: 1,
				                title: "&nbsp;",
							    area: ['384px', '186px'],
							    border: [1, 1, '#cecfd0'],
							    time:3000,
							    content: '<div class="tipsWrap w384"><div class="tipsTxt"><i class="iconfont okIco">&#xe63d;</i><span>添加银行卡成功</span></div><div class="tipsMsg">3秒后窗口自动关闭</div></div>',
							    cancel: function(index){
							    	window.location.href = "/member/cash/bank.html";
							    },
							    end: function(){
							    	window.location.href = "/member/cash/bank.html";
							    },
							    success: function(layero){
							    	var time =3; 
							    	function closeTime () {
										time--;
										$(".tipsMsg").html(time+"秒后窗口自动关闭");
    								}
							    	setInterval(function(){
										closeTime();
									}, 1000);
							    }
							});
    					}else{
    						window.layer.open({
							    type: 1,
							    closeBtn: 1,
	                		    title: "&nbsp;",
							    area: ['384px', '186px'],
							    border: [1, 1, '#cecfd0'],
							    content: '<div class="tipsWrap w384"><div class="tipsTxt"><i class="iconfont errIco">&#xe63e;</i><span>'+data.msg+'</span></div><div class="tipsBtnBar"><a href="javascript:;" class="okBtn failBtn">确定</a></div></div>',
							    cancel: function(index){
							    	layer.closeAll();
							    }
							});
    						$(".failBtn").click(function(){
    							layer.closeAll();
							});
    					}
					}
				});				
			}
		});
	
	
/*$(function(){
	jQuery(".prov").change(function(){
		var province = jQuery(this).val();
		var count = 0;
		jQuery.ajax({
			url:"/tpp/tppMmmAction/showMmmBankArea.html",
			dataType:'json', 
			data:"pid="+province,
			success:function(json){
				jQuery(".city option").each(function(){
					jQuery(this).remove();				 
				});
				jQuery("<option value='0'>请选择</option>").appendTo(".city");
				jQuery(json).each(function(){
					jQuery("<option value='"+json[count].nid+"'>"+json[count].name+"</option>").appendTo(".city");
					count++;
				});
			}
		});
	});
	
});	*/
	
	//加载城市选择插件
	require.async('jquery-citySelect/jquery.cityselect',function(){
		$("#city").citySelect({
			url:"../../../themes/theme_default/media/js/jquery-citySelect/city_sina.json",
			prov:"上海", //省份 
			city:"", //城市 
			dist:"", //区县 
		    required:false
		});
	})
	
	
	
	
	
});